{yun:}include file="$wapstyle/member/cheader.htm"{/yun}
<section class="wap_member">
    {yun:}foreach item=v from=$rows{/yun}
        <div class="com_member_hr">
            <div class="com_member_hr_name">
                <a href="javascript:void(0);" class="wap_member_com_name  com_member_hr_cblue">{yun:}$v.username{/yun}</a>
            </div>
            <div class="com_member_user_box">
                <div class="com_member_hr_tj">
                    <div class="com_member_hr_p1">
                        <span class="member_c9">子账号ID：</span> {yun:}$v.uid{/yun} &nbsp;&nbsp;&nbsp;

                        <span class="member_c9">部门名称：</span>{yun:}$v.name{/yun} &nbsp;&nbsp;&nbsp;

                     </div>
                </div>
                <div class="com_member_hr_p1">
                    <span class="member_c9">添加日期：{yun:}$v.ctime|date_format:'%Y-%m-%d '{/yun}</span>
                </div>
            </div>
            <div class="com_member_hr_cz">
                
                <a href="javascript:;" class="yun_member_hr_bth bindChildA" data-uid="{yun:}$v.uid{/yun}">删除</a>
                {yun:}if $v.status == 2{/yun}
            		<a href="javascript:void(0);" onclick="activeSon('{yun:}$v.uid{/yun}');" class="yun_member_hr_bth">激活</a>
                {yun:}else{/yun}
	                <a href="index.php?c=childassign&cuid={yun:}$v.uid{/yun}" class="yun_member_hr_bth">分配套餐</a>
	                <a href="index.php?c=childedit&cuid={yun:}$v.uid{/yun}" class="yun_member_hr_bth">修改</a>
                {yun:}/if{/yun}
            </div>
        </div>
    {yun:}foreachelse{/yun}
        <div class="wap_member_no">目前您还没有创建子账号<div>
    {yun:}/foreach{/yun}
</section>
<div class="pages">{yun:}$pagenav{/yun}</div>

<script type="text/javascript">
   
    //删除
    $('.bindChildA').on('click', function () {
    	
        var thisChildId = parseInt($(this).attr('data-uid'));
        if (isNaN(thisChildId) || thisChildId < 1) {
            layermsg('子账号数据错误！');
            return false;
        }
         
		layer.open({
			content: '删除会子账号将无法恢复',
			btn: ['确认', '取消'],
			shadeClose: false,
			yes: function(){
				layer.closeAll();
                layer_load('执行中，请稍候...');
                $.post("index.php?c=delChild", { uid: thisChildId }, function (data) {
                    layer.closeAll();
                    var res = eval('(' + data + ')');
                    if (res.ecode == 9) {
                        layermsg(res.msg, 2, function () { location.reload(); });
                    } else {
                        layermsg(res.msg);
                    }
                    return false;
                });
			} 
		}); 
    });

    //分配套餐输入数据格式化
    $('.numCheck').on('keyup', function(){
        $(this).val($(this).val().replace(/[^0-9.]/g,''));
    });

    //分配套餐弹出框，获取已经分配的套餐
    $('.assignChildA').on('click', function () {
        var thisChildId = parseInt($(this).attr('data-uid'));
        if (isNaN(thisChildId) || thisChildId < 1) {
            layermsg('子账号数据错误！');
            return false;
        }
        $('#assignChildValId').val(thisChildId);
        layer_load('查询中，请稍候...', 0);
        $.post("index.php?c=child&act=getstatis", { uid: thisChildId }, function (data) {
            layer.closeAll();
            var res = eval('(' + data + ')');
            if (res.ecode == 9) {
                if (res.data.fathers != undefined) {
                    //设置主会员数据
                    var fatherObj = res.data.fathers;
                    var sonObj = res.data.sons;
                    $('#currentRateNameId').text(fatherObj.rating_name);
                    $('#currentRateTypeId').text(fatherObj.rating_type_name);
                    $('#vipTimeId').text(fatherObj.vip_stime_str + ' - ' + fatherObj.vip_etime_str);
                    //需要分配的字段数量
                    for (i = 0; i < assignField.length; i++){
                        var tmpFie = assignField[i];
                        if(fatherObj[assignField[i]] != undefined){
                            $('#f'+assignField[i]+'Id').val(fatherObj[assignField[i]]);
                        }
                        if(sonObj[assignField[i]] != undefined){
                            $('#s'+assignField[i]+'Id').val(sonObj[assignField[i]]);
                        }
                    }
                    //显示弹出层
                    var layindex = $.layer({
                        type: 1,
                        title: '分配套餐',
                        closeBtn: [0, true],
                        border: [10, 0.3, '#000', true],
                        area: ['520px', '400px'],
                        page: { dom: "#assignstatis_box" }
                    });
                    $("#layindex").val(layindex);
                }
            } else {
                layermsg(res.msg);
            }
            return false;
        });
    }); 
    
    function activeSon(spid){
    	
    	layer_load('执行中，请稍候...', 0);
    	
        $.post("index.php?c=activeSon", { spid: spid }, function (data) {
            
        	layer.closeAll();
            
            var res = eval('(' + data + ')');
            
            if (res.ecode == 9) {
            	
            	layermsg(res.msg, 2, function () { location.reload(); });
            } else {
            	
            	if(res.ecode == 55){
            		
            		if(res.msg == '您的会员已到期' || res.msg == '您的套餐数量已用完'){
            			layer.open({
        					title 	: [ '温馨提示', 'background-color: #FF4351; color:#fff;' ],
                            content	: res.msg+'，可以先购买会员套餐？',
                            btn	: ['继续', '取消'],
                            shadeClose	: false,
                            yes	: function() {
                                 window.location.href = "index.php?c=server&server=son";
                            }
                        });	
            		}else{
            			
            			layermsg(res.msg);
            		}	
            	}
            }
            return false;
        });
    	
    }

</script>

{yun:}include file="$wapstyle/footer.htm"{/yun}